const mongoose = require('mongoose');
const User = require('./models/User.js');
const dotenv = require('dotenv');
(async () => {
  try {
    dotenv.config({
      path: './config/config.env.development'
    });
    mongoose.set('strictQuery', true);
    console.log('Mongodb is connecting');
    await mongoose.connect(process.env.LOC_MONGO_URI).then(() => {
      console.log('Mongodb is connected');
    });

    const email = 'zhongyi.li@qq.com';
    const password = '123';

    await User.register(new User({email, username: email, role: 'admin'}), password);

    console.log('User created successfully.');
  } catch (err) {
    console.error('err', err.message);
  } finally {
    process.exit(0);
  }
})();
